package ks.client.gui.admin.plugin.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JTextField;
import ks.client.controllers.admincommands.PluginUnsuspendCommand;
import ks.client.controllers.commands.PluginListCommandController;
import ks.client.gui.ErrorMessageGUI;
import ks.client.lobby.Lobby;


/**
 * 
 * Listens for the "Unsuspend" button to be clicked
 * and creates an UnsuspendCommand.
 * 
 * @author Jennifer Hunt
 *
 */
public class UnsuspendClick implements ActionListener{
	
	Lobby lobby;
	JTextField name;
	
	/**
	 * UnsuspendClick controller.
	 * 
	 * @param lobby
	 * @param table
	 */
	public UnsuspendClick(Lobby lobby, JTextField name) {
		this.lobby = lobby;
		this.name = name;
	}

	/**
	 * 
	 * Button is clicked. 
	 * 
	 */
	public void actionPerformed(ActionEvent e){
		if(name.getText().isEmpty()){
				JFrame pma = new ErrorMessageGUI("Please input a plugin name.");
				pma.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
				pma.setTitle("Error");
				pma.setVisible(true);
			}
		else{
			new PluginUnsuspendCommand(lobby).send(name.getText());
			new PluginListCommandController(lobby).send();
		}
	}
}
